package Day7;

public class User implements Comparable<User> {
    private String id;
    private String name;

    // 修复构造函数，接受int和String参数
    public User(int id, String name) {
        this.id = String.valueOf(id);
        this.name = name != null ? name : ""; // 防止name为null
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public int compareTo(User o) {
        // 添加空值检查以避免NullPointerException
        if (this.id == null && o.id == null) {
            return 0;
        }
        if (this.id == null) {
            return -1;
        }
        if (o.id == null) {
            return 1;
        }
        return this.id.compareTo(o.id);
    }

    @Override
    public String toString() {
        return "User{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                '}';
    }
}
